package com.xiangban.xiangbanmall.controller;

import com.xiangban.xiangbanmall.aop.Permission;
import com.xiangban.xiangbanmall.model.TUser;
import com.xiangban.xiangbanmall.model.TUserMember;
import com.xiangban.xiangbanmall.model.res.ApiResult;
import com.xiangban.xiangbanmall.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/10/26 15:34
 */
@RestController
@RefreshScope
@RequestMapping("/api/mall/user")
@Api(value = "用户信息管理")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/add_user")
    @ApiOperation("添加用户基本信息")
//    @Permission
    public ApiResult<Object> addTUser(@RequestBody TUser tUser){
        userService.addTUser(tUser);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/update_user")
    @ApiOperation("修改用户基本信息")
    @Permission
    public ApiResult<Object> updateTUser(@RequestBody TUser tUser){
        userService.updateTUser(tUser);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/get_user_Info")
    @ApiOperation("获取用户信息")
    public ApiResult<Object> getUserInfo(){
        return ApiResult.newSuccess(userService.getTUser());
    }


    @RequestMapping("/update_open_id_by_id")
    @ApiOperation("根据用户id改open_id")
    public ApiResult<Object> updateOpenIdById(@RequestBody TUser tUser){
        userService.updateOpenIdById(tUser);
        return ApiResult.newSuccess();
    }
}
